package com.linh.trade;

import static com.linh.trade.Constants.AMOUNT_FORMAT;

import java.io.FileOutputStream;
import java.io.PrintWriter;

public class Output implements TraderActionListener {

	String outputFile;
	PrintWriter printWriter;

	public Output(String outputFile) throws Exception {
		super();
		this.outputFile = outputFile;
		printWriter = new PrintWriter(new FileOutputStream(outputFile, false));
	}

	public void onGoingLong(Trade trade, double budget) {
		printWriter.println(trade.getOpenLine() + " ("
				+ AMOUNT_FORMAT.format(budget) + ")");
		printWriter.flush();

	}

	public void onGoingShort(Trade trade, double budget) {
		printWriter.println(trade.getOpenLine() + " ("
				+ AMOUNT_FORMAT.format(budget) + ")");
		printWriter.flush();
	}

	public void onPositionClosed(Trade trade, double budget) {
		printWriter.println(trade.getCloseLine() + " ("
				+ AMOUNT_FORMAT.format(budget) + ")");
		printWriter.flush();
	}

	public void close() throws Exception {
		printWriter.close();
	}

}
